import 'package:flutter/material.dart';



class Tabs extends StatefulWidget {
  final Function(int) switchBottomNavigationBar;
  const Tabs({ Key? key,required this.switchBottomNavigationBar }) : super(key: key);

  @override
  _TabsState createState() => _TabsState();
}

class _TabsState extends State<Tabs> {
  int _currentIndex=0;
  @override
  Widget build(BuildContext context) {
    return BottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: (index) {
          setState(() {
            _currentIndex=index;
          });
          //访问到父组件传入的回调函数
          widget.switchBottomNavigationBar(index);
        },
        items: const [
          BottomNavigationBarItem(icon: Icon(Icons.home_outlined), label: "首页"),
          BottomNavigationBarItem(icon: Icon(Icons.people), label: "我的"),
        ],
      );
  }
}